package com.example.mobile2121606110syc0501homework;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import java.util.List;

public class StudentRViewAdapter2 extends RecyclerView.Adapter<StudentRViewAdapter2.ViewHolder>{
    List<Student>list2;
    public StudentRViewAdapter2(List<Student> list){
        this.list2 = list;
    }
    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_rv_main_student,null);
        ViewHolder viewHolder = new ViewHolder(view);
        return viewHolder;
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
        Student student = list2.get(position);
        holder.tvName.setText(student.getName());
        holder.tvNum.setText(String.valueOf(student.getNum()));
        holder.tvSex.setText(student.getSex());
        holder.tvPos.setText(student.getPos());

    }

    @Override
    public int getItemCount() {
        return list2.size();
    }

    static class ViewHolder extends RecyclerView.ViewHolder{
        TextView tvName,tvNum,tvSex,tvPos;
        public ViewHolder(@NonNull View itemView){
            super(itemView);
            this.tvName = itemView.findViewById(R.id.tvItemName);
            this.tvNum = itemView.findViewById(R.id.tvItemNum);
            this.tvSex = itemView.findViewById(R.id.tvItemSex);
            this.tvPos = itemView.findViewById(R.id.tvItemPos);
        }
    }
}
